package com.coocaa.internship.util;

import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

/**
 * @Description: 文件上传util
 * @Author: zwh
 * @Date: 2019-07-29
 * @Time: 17:05
 */
public class FileUploadUtil {
    /**
     * @param file 原始文件
     * @param path 存储路径
     * @return
     */
    public static boolean upload(MultipartFile file, String path) {
        try {
            File trueFile = new File(path);
            if (!trueFile.getParentFile().exists()) {
                trueFile.getParentFile().mkdirs();
            }
            file.transferTo(trueFile);
            return true;
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
    }
}
